#pragma once
#include <geometry\primitive.h>
#include <physics\rigid_body.h>
#include <lbvh\lbvh.h>


namespace gc {
	inline Float genRand(Float L, Float R) {
		return L + (R - L)*Float(rand()) / RAND_MAX;
	}

	inline Point3f uniformSampleDirection() {
		Float theta = genRand(0, PI);
		Float phi = genRand(0, 2 * PI);
		Float sintheta = sin(theta);
		Float costheta = cos(theta);
		return { sintheta*cos(phi),costheta,sintheta*sin(phi) };
	}

	class BouncingBallSimulation {
	private:
		SimpleBox sceneBox;
		Float lx, ly, lz;
		Point3f base;
		int n_prims;
		LBvh lbvh;
		SimpleSphere* d_balls;
		MPhys::RigidBody* d_rigids;
		thrust::device_vector<CollisionPair> d_cp;

		Float dt;  // time per frame in seconds
		int frame;
	public:
		BouncingBallSimulation(SimpleBox &sceneBox);
		~BouncingBallSimulation();

		void setTimePerFrame(Float dt);

		void generateBalls(int number);

		void produceFrame();
	};

}